package BeanTest;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.io.ClassPathResource;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 *	“ SpringAOP ”
 * 	exposeProxy = true的时候，Spring会把当前对象的代理对象 存放在ThreadLocal中.在后续代码中可以得到代理对象
 *	这个 @EnableAspectJAutoProxy 注解 通过 @Import 引入了一个beanpostprocessor: AnnotationAwareAspectJAutoProxyCreator
 *
 **/
@EnableAspectJAutoProxy(exposeProxy = true)


/**
 * “ Spring事务 ”
 *  Spring事务跟AOP类似，也是先通过BeanPostProcessor 创建代理，然后在运行时(invoke方法)进行原始方法和额外功能的整合
 *  同样的，这个 @EnableTransactionManagement 注解 通过import 引入了一个beanpostprocessor: TransactionManagementConfigurationSelector
 */
@EnableTransactionManagement



public class BeanTest {
	public static void main(String[] args) {
		/*ApplicationContext applicationContext =
				new ClassPathXmlApplicationContext("spring-config.xml");
		System.out.println(applicationContext.getBean(TestBean.class).getName());*/

		/**
		 * getObject方法
		 */
		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
		TestBean testBean = (TestBean) beanFactory.getBean("testBean");

		/**
		 * SpringIOC
		 */
		ApplicationContext context = new AnnotationConfigApplicationContext(BeanTest.class);
	}

}
